package com.inplaceedit.client.activity.menu;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.core.gwt.ui.client.HyperLabel;
import com.core.gwt.ui.client.HyperString;

public class MenuView extends Composite implements MenuActivityImpl.View {

	interface Binder extends UiBinder<Widget, MenuView> {
	}

	private static Binder uiBinder = GWT.create(Binder.class);

	@UiField
	HyperLabel menu;

	public MenuView() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public void setItems(final List<HyperString> items) {
		final StringBuilder b = new StringBuilder();
		for (int i = 0; i < items.size(); i++) {
			if (i > 0) {
				b.append(" | ");
			}
			b.append("{");
			b.append(i);
			b.append("}");
		}
		if (items.size() > 0) {
			HyperString[] args = new HyperString[items.size()];
			args = items.toArray(args);
			menu.setText(b.toString(), args);
		} else {
			menu.setText(b.toString());
		}
	}

}
